<template>
  <div class="main-content">

    <div class="header container mb-4 pt-2">
      <div class="header-body border-bottom py-4">
        <div class="row align-items-end">
          <div class="col">
            <h2 class="header-title">
              Jupiter 模块生成
            </h2>
          </div>
          <div class="col-auto">
          </div>
        </div>
      </div>
    </div>

    <div class="container px-4">

      <div class="mb-3">
        <label for="dir">模块的父目录</label>
        <input type="text" class="form-control" id="dir" v-model="formData.dir" >
      </div>

      <div class="mb-3">
        <label for="name">模块的名称 </label>
        <input type="text" class="form-control" id="name" v-model="formData.name" placeholder="建议首字母大写的单词加横杠如: Jupiter-Server-System">
      </div>

      <div class="mb-3">
        <label for="name">模块的包名 </label>
        <input type="text" class="form-control" id="package" v-model="formData.packageName">
      </div>

      <div class="mb-3">
        <label for="desc">模块的描述 </label>
        <input type="text" class="form-control" id="desc" v-model="formData.desc">
      </div>

      <div class="form-group form-check mb-3">
        <input type="checkbox" class="form-check-input" id="checkCommon" v-model="formData.isNeedCommon">
        <label class="form-check-label" for="checkCommon">是否包含Common模块</label>
      </div>

      <div class="mt-5">
        <button type="button" class="btn btn-primary btn-sm" @click="submit"> 生成模块
        </button>
      </div>
    </div>
  </div>
</template>

<script>
  module.exports = {
    name: 'GeneratorModule',
    data() {
      return {
        searchName: '',
        formData: {
          dir: "/Users/edgar/workspace",
          name: "Jupiter-Server-System", // limit item size in a page
          desc: "Jupiter后台管理系统微服务模块",
          packageName: "com.edgardeng.jupiter",
          isNeedCommon: false
        },
      }
    },
    created () {
      let item = window.localStorage.getItem("generator.module")
      if (!item || item === 'undefined') {
        return
      }
      let result = JSON.parse(item)
      this.formData.dir = result.dir
      this.formData.name = result.name
      this.formData.desc = result.desc
      this.formData.packageName = result.packageName
      if (result.isNeedCommon) {
        this.formData.isNeedCommon = true
      }
    },
    methods: {
      submit() {
        // 保存参数 下次使用
        window.localStorage.setItem("generator.module", JSON.stringify(this.formData))
        this.$emit('generate', this.formData)
      }
    }
  }
</script>
